#include <stdio.h>
int binary_search(int sz ,int k,int arr[])
{
	int left = 0;
	int right = sz;
	while (left <= right) 
	{
		int maid = (left + right) / 2;
		if (arr[maid] > k)
		{
		 right = maid - 1;
		}
		else if (arr[maid] < k)
		{
		left = maid + 1;
		}
		else
		{
			return maid;
		}
        return -1;
	}
}
int main()
{
	int arr[] = { 1,2,3,4,5,6,7,8,9,10};
	int k = 8;
	int sz = sizeof(arr) / sizeof(arr[0])-1;
	int ret = binary_search(sz, k, arr);
	if (-1 == ret)
	{
		printf("找不到");
	}
	else
	{
		printf("找到了，下标是：%d", ret);
	}
	return 0;
}